package com.smf.lsc.authorization.security.captcha.util;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * 验证码校验工具类
 * @author ln
 *
 */
@Service
public class CodeUtil {
	@Autowired
    private RedisTemplate<String, String> redisTemplate;
    /**
     * 验证码校验
     * @param request
     * @return
     */
    public boolean checkVerifyCode(HttpServletRequest request,String verifyCodeActual,String codeRandom) {
        //获取生成的验证码
//        String verifyCodeExpected = (String) request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);
    	String  verifyCodeExpected =redisTemplate.opsForValue().get(codeRandom);
    	//获取用户输入的验证码
        if(verifyCodeActual.equals(verifyCodeExpected)) {
        	redisTemplate.delete(codeRandom);
            return true;
        }
        return false;
    }
}